#include <iostream>
#include <set>
using namespace std;

int main() {
    int n;
    cin >> n;
    set<pair<int, int>> intervals;
    int count = 0;

    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;

        auto it = intervals.lower_bound({ l, -1 });
        bool overlap = false;

        if (it != intervals.end() && it->first <= r) {
            overlap = true;
        }

        if (!overlap && it != intervals.begin()) {
            auto prev_it = prev(it);
            if (prev_it->second >= l) { 
                overlap = true;
            }
        }

        if (!overlap) {
            count++;
            intervals.insert({ l, r });
        }
    }

    cout << count << endl;
    return 0;
}